<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="en">
<head>
    <%@include file="/WEB-INF/views/include/weixinhead.jsp" %>
    <script src="${ctxStatic}/modules/wechat/js/rip.js"></script>
</head>
<body>
<!--勤工与就业-->
<div data-role="page" id="compus-msg" class="page" >
    <div data-role="header" class="header header-1">勤工与就业
        <span class="return-btn"><a href="/f/campusinfo/homepage" data-ajax="false" data-transition="slideup"><img src="${ctxStatic}/modules/wechat/css/images/yuanjiaojuxing25.png" alt=""></a></span>
        <span><a href="" data-ajax="false" data-transition="slideup"><span></span></a></span>
    </div>
    <div role="main" class="content-1">
        <div id="work-msg-title">
            <!--<span class="title-span title-span-active" classifyId="0">所有</span>-->
            <span class="title-span" classifyId="1">勤工俭学</span>
            <span class="title-span" classifyId="2">就业</span>
        </div>
        <div id="work-msg"></div>
        <div class="iframeOverflowYHidden">
            <iframe id="Loading" src="/f/campusinfo/LoadingOfResources" style="width: 100%;height:42px;" frameborder="0"></iframe>
            <iframe id="complete" src="/f/campusinfo/completeLoadingOfResources" frameborder="0" style="width: 100%;height:42px;"></iframe>
            <iframe id="errorLoad" src="/f/campusinfo/errorLoadingResources" frameborder="0" style="width: 100%;height:42px;display: none"></iframe>
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        // //使iframe高度自适应屏幕
        // $(".content-1").eq(0).css("height",window.screen.height-96+"px");
        var totalNum=0;  //总加载页数
        var pageNumber=0; //当前加载页数
        var classifyId=1;   //当前选择分类
        //默认显示勤工
        $(".title-span").eq(0).addClass("title-span-active");
        startStuJobList(interfaceStuJobList);
        var url=window.location.href;  //获取页面url

        //勤工、就业标题选中事件
        $(".title-span").on("tap", function (event) {
            pageNumber=0;
            $(this).addClass("title-span-active").siblings().removeClass("title-span-active");
            classifyId=$(this).attr("classifyId");
            // console.log("classify"+classifyId);
            if(classifyId==1){
                $("#Loading").show();  //显示“加载中”提示
                $("#work-msg").html("");
                startStuJobList(interfaceStuJobList);   //勤工，参数查阅interface.js
            }else if(classifyId==2){
                $("#Loading").show();  //显示“加载中”提示
                $("#work-msg").html("");
                startBusinessList(interfaceJobList);     //就业，参数查阅interface.js
            }
        });
        //就业信息请求
        function startBusinessList(inter) {
            // console.log(pageNumber+":"+totalNum);
            if(pageNumber<=totalNum){
                //ajax请求返回信息的标题、简介、图片以及id
                $.ajax({
                    url:inter,                                             //接口
                    type:"post",
                    data:{pageNo:pageNumber++},
                    error:function(XMLHttpRequest, textStatus, errorThrown) {
                        // console.log(textStatus+XMLHttpRequest.status+XMLHttpRequest.readyState);
                        $("#Loading").hide();      //隐藏“加载中”提示
                        $("#errorLoad").show();  //显示“加载失败”提示
                    },
                    success:function (data) {
                        // console.log(data);
                        if(data.success){
                            $("#Loading").hide();  //隐藏“加载中”提示
                            $("#complete").show();  //显示底部“加载完成”提示
                            var count=data.page.length;
                            for(var i=0;i<count;i++){
                                if(!data.page[i].jobImg){
                                    data.page[i].jobImg="${ctxStatic}/modules/wechat/css/images/sx-img.png";
                                }
                                // var reg=/<\/?[^>]*>/g;
                                var jobName=data.page[i].jobStype;
                                // if(jobName!=''){
                                //     jobName=jobName.replace(reg,'');
                                // }
                                var jobContent=data.page[i].jobShort;
                                // if(jobContent!=''){
                                //     jobContent=jobContent.replace(reg,'')
                                // }
                                $("#work-msg").append("<div class='msg-div' id="+data.page[i].id+"><div class='msg-content-left'> <div class='msg-div-title'>"+jobName+"&nbsp;&nbsp;("+data.page[i].jobName+")</div><div class='msg-div-text'>"+jobContent+"</div> </div> <img onerror=\"this.onerror='';src='${ctxStatic}/modules/wechat/css/images/sx-img.png'\" src='${imgIp}"+data.page[i].jobImg+"'></div>");
                            }
                            //点击信息，查看详情
                            $(".msg-div").bind("click",function () {
                                if(window.sessionStorage){
                                    sessionStorage.setItem("msgID",$(this).attr("id"));
                                    sessionStorage.setItem("classify",classifyId);
                                }else {
                                    window.location.href="/f/campusinfo/detailsPage?id="+$(this).attr("id")+"&classify="+classifyId+generateMixed(9);
                                }
                            });
                        }else {
                            // console.log(data.message);
                        }
                        totalNum=data.totalPage;
                    }
                });
            }else{
                //已经加载完毕
                // console.log("已经加载完毕");
            }
        }
        //勤工信息请求
        function startStuJobList(inter) {
            if(pageNumber<=totalNum){
                //ajax请求返回信息的标题、简介、图片以及id
                $.ajax({
                    url:inter,                                             //接口
                    type:"post",
                    data:{},
                    error:function(XMLHttpRequest, textStatus, errorThrown) {
                        $("#Loading").hide();      //隐藏“加载中”提示
                        $("#errorLoad").show();  //显示“加载失败”提示
                    },
                    success:function (data) {
                        // console.log(data);
                        if(data.success){
                            $("#Loading").hide();  //隐藏“加载中”提示
                            $("#complete").show();  //显示底部“加载完成”提示
                            var count=data.page.length;
                            for(var i=0;i<count;i++){
                                if(!data.page[i].redImg){
                                    data.page[i].redImg="css/images/sx-img.png";
                                }
                                // var reg=/<\/?[^>]*>/g;
                                var jobName=data.page[i].redStype;
                                // if(redName!=''){
                                //     redName=redName.replace(reg,'');
                                // }
                                var jobContent=data.page[i].redShort;
                                // if(redContent!=''){
                                //     redContent=redContent.replace(reg,'')
                                // }
                                $("#work-msg").append("<div class='msg-div' id="+data.page[i].id+"><div class='msg-content-left'> <div class='msg-div-title'>"+jobName+"&nbsp;&nbsp;("+data.page[i].reqName+")</div><div class='msg-div-text'>"+jobContent+"</div> </div> <img onerror=\"this.onerror='';src='${ctxStatic}/modules/wechat/css/images/cy-img.png'\" src='${imgIp}"+data.page[i].redImg+"'></div>");
                            }
                            //点击信息，查看详情
                            $(".msg-div").bind("click",function () {
                                if(window.sessionStorage){
                                    sessionStorage.setItem("msgID",$(this).attr("id"));
                                    sessionStorage.setItem("classify",classifyId);
                                }else {
                                    window.location.href="/f/campusinfo/detailsPage?id="+$(this).attr("id")+"&classify="+classifyId+generateMixed(9);
                                }
                            });
                        }else {
                            alert(data.message);
                        }
                        totalNum=data.totalPage;
                    }
                });
            }else{

                //已经加载完毕

            }

        }

        //判断是否是移动设备
        function isMobile() {
            if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))){
                return true;
            }
            else{
                return false;
            }
        }
        //根据滑动异步加载
        var presentScrollTop=0;
        if (isMobile()){
            //移动端监听滑动
            $("#work-msg").on("scrollstart",function() {
                scrollTop=$(window).scrollTop();   //当前据顶部距离
                if(scrollTop-presentScrollTop>400){
                    if(pageNumber<totalNum){
                        presentScrollTop=scrollTop;
                        if(classifyId==1){
                            $("#Loading").hide();  //隐藏“加载中”提示
                            $("#complete").show();  //显示底部“加载完成”提示
                            startStuJobList(interfaceStuJobList);   //勤工，参数查阅interface.js
                        }else if(classifyId==2){
                            $("#Loading").hide();  //隐藏“加载中”提示
                            $("#complete").show();  //显示底部“加载完成”提示
                            startBusinessList(interfaceJobList);     //就业，参数查阅interface.js
                        }
                    }else {
                        // console.log("已经加载完毕");
                    }
                }
            });
        }else{
            //pc端监听滚动
            $(document).scroll(function() {
                scrollTop=$(window).scrollTop();   //当前据顶部距离
                if(scrollTop-presentScrollTop>400){
                    if(pageNumber<totalNum){
                        presentScrollTop=scrollTop;
                        if(classifyId==1){
                            $("#Loading").hide();  //隐藏“加载中”提示
                            $("#complete").show();  //显示底部“加载完成”提示
                            startStuJobList(interfaceStuJobList);   //勤工，参数查阅interface.js
                        }else if(classifyId==2){
                            $("#Loading").hide();  //隐藏“加载中”提示
                            $("#complete").show();  //显示底部“加载完成”提示
                            startBusinessList(interfaceJobList);     //就业，参数查阅interface.js
                        }
                    }else {
                        // console.log("已经加载完毕");
                    }
                }
            });
        }
        //点击信息，查看详情
        $(document).delegate(".msg-div","tap",function () {
            var index=$(".msg-div").index($(this));
            if(window.sessionStorage){
                sessionStorage.setItem("msgID",$(this).attr("id"));
                sessionStorage.setItem("classify",classifyId);
                window.location.href="/f/campusinfo/detailsPage"+generateMixed(9);
            }else {
                window.location.href="/f/campusinfo/detailsPage?id="+$(this).attr("id")+"&classify="+classifyId+generateMixed(9);
            }
        });
    })
</script>
</body>
</html>